package cn.edu.ujn.project.supermarket.controller;

import java.util.List;

import cn.edu.ujn.project.supermarket.mapper.ChargeReportMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.ujn.project.common.annotation.Log;
import cn.edu.ujn.project.common.core.controller.BaseController;
import cn.edu.ujn.project.common.core.domain.AjaxResult;
import cn.edu.ujn.project.common.core.page.TableDataInfo;
import cn.edu.ujn.project.common.enums.BusinessType;
import cn.edu.ujn.project.common.utils.poi.ExcelUtil;
import cn.edu.ujn.project.supermarket.domain.ChargeReport;
import cn.edu.ujn.project.supermarket.extendbean.ChargeReportChild;
import cn.edu.ujn.project.supermarket.service.IChargeReportService;

/**
 * 充值记录表Controller
 * 
 * @author zhaomh
 * @date 2023-11-13
 */
@Controller
@RequestMapping("/system/report")
public class ChargeReportController extends BaseController
{
    private String prefix = "system/report";

    @Autowired
    private IChargeReportService chargeReportService;

    @RequiresPermissions("system:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    /**
     * 查询充值记录表列表
     */
    @RequiresPermissions("system:report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ChargeReportChild chargeReport)
    {
        startPage();
        List<ChargeReportChild> list = chargeReportService.selectChargeReportChildList(chargeReport);
//        List<ChargeReportChild> list = chargeReportDao.selectChargeReportChildList(chargeReport);
//        System.out.println(list.size());
//        System.out.println(getDataTable(list).getRows());
        return getDataTable(list);
    }

    /**
     * 导出充值记录表列表
     */
    @RequiresPermissions("system:report:export")
    @Log(title = "充值记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChargeReportChild chargeReport)
    {
        List<ChargeReportChild> list = chargeReportService.selectChargeReportChildList(chargeReport);
        ExcelUtil<ChargeReportChild> util = new ExcelUtil<ChargeReportChild>(ChargeReportChild.class);
        return util.exportExcel(list, "充值记录表数据");
    }

    /**
     * 新增充值记录表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存充值记录表
     */
    @RequiresPermissions("system:report:add")
    @Log(title = "充值记录表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChargeReport chargeReport)
    {
        return toAjax(chargeReportService.insertChargeReport(chargeReport));
    }

    /**
     * 修改充值记录表
     */
    @RequiresPermissions("system:report:edit")
    @GetMapping("/edit/{chargeId}")
    public String edit(@PathVariable("chargeId") String chargeId, ModelMap mmap)
    {
        ChargeReport chargeReport = chargeReportService.selectChargeReportByChargeId(chargeId);
        mmap.put("chargeReport", chargeReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值记录表
     */
    @RequiresPermissions("system:report:edit")
    @Log(title = "充值记录表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChargeReport chargeReport)
    {
        return toAjax(chargeReportService.updateChargeReport(chargeReport));
    }

    /**
     * 删除充值记录表
     */
    @RequiresPermissions("system:report:remove")
    @Log(title = "充值记录表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chargeReportService.deleteChargeReportByChargeIds(ids));
    }
}
